﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Payroll
{
    class Cipher
    {
        public static void Encryption(string filePath)
        {
            FileStream readFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            byte[] bytes = new byte[readFileStream.Length];
            readFileStream.Read(bytes, 0, bytes.Length);
            readFileStream.Close();
            for (int i = 0; i < bytes.Length; i++)
            {
                ++bytes[i];
            }
            string newPath = filePath.Insert(filePath.LastIndexOf('.'), "-encryption");
            FileStream writeFileStream = new FileStream(newPath, FileMode.Create, FileAccess.Write);
            writeFileStream.Write(bytes, 0, bytes.Length);
            writeFileStream.Close();

            myFile.delete(filePath);
            Console.WriteLine("加密完成");
        }

        public static void Decryption(string filePath)
        {
            FileStream readFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            byte[] bytes = new byte[readFileStream.Length];
            readFileStream.Read(bytes, 0, bytes.Length);
            readFileStream.Close();
            for (int i = 0; i < bytes.Length; i++)
            {
                --bytes[i];
            }
            string newPath = filePath.Insert(filePath.LastIndexOf('.'), "-decryption");
            FileStream writeFileStream = new FileStream(newPath, FileMode.Create, FileAccess.Write);
            writeFileStream.Write(bytes, 0, bytes.Length);
            writeFileStream.Close();
            Console.WriteLine("解密完成");
        }
    }
}
